package com.woniuxy.mesboot.service.impl;

import com.woniuxy.mesboot.entity.MesTeam;
import com.woniuxy.mesboot.mapper.MesTeamMapper;
import com.woniuxy.mesboot.mapper.MesTeamMembersMapper;
import com.woniuxy.mesboot.service.TeamService;
import com.woniuxy.mesboot.vo.TeamVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TeamServiceImpl implements TeamService {
    @Resource
    private MesTeamMapper teamMapper;

    @Resource
    private MesTeamMembersMapper teamMembersMapper;

    @Override
    @Transactional
    public List<TeamVO> selectAllName(Long id) {
        List<TeamVO> teamVOS = teamMapper.selectAllName(id);
        for (int i = 0; i < teamVOS.size(); i++) {
            Integer teamId = teamVOS.get(i).getTeamId();
            teamVOS.get(i).setTeamMemberVOList(teamMembersMapper.selectListById(Long.valueOf(teamId)));
        }
        return teamVOS;
    }

    @Override
    public List<MesTeam> selectAll() {
        return teamMapper.selectAll();
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return teamMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(MesTeam record) {
        return teamMapper.insert(record);
    }

    @Override
    public int insertSelective(MesTeam record) {
        return teamMapper.insertSelective(record);
    }

    @Override
    public MesTeam selectByPrimaryKey(Long id) {
        return teamMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(MesTeam record) {
        return teamMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(MesTeam record) {
        return teamMapper.updateByPrimaryKey(record);
    }
}
